package Chapter3;

import java.util.Scanner;

public class Caculater {
    public static void main(String[] args) {
        //定义三个变量
        double result = 0;
        String op = "";
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入要计算的数字:");
        try{
            result = sc.nextDouble();
        }catch (Exception e){
            return;
        }
        System.out.println("请输入运算符:");
        op = sc.next();
        do{
            System.out.println("请输入要计算的数字:");
            double num1 = sc.nextDouble();
            switch (op){
                case "+":
                    result += num1;
                    break;
                case "-":
                    result -= num1;
                    break;
                case "*":
                    result *= num1;
                    break;
                case "/":
                    try{
                        result /= num1;
                    }catch (Exception e){
                        System.out.println("除数不能为0");
                        return;
                    }

                    break;
            }
            System.out.println("请输入运算符:");
            op = sc.next();
        }while (!op.equals("="));
        System.out.println("计算结果:" + result);
    }
}
